﻿<%@ WebHandler Language="C#" Class="ImgUpload" %>

using System;
using System.Web;
using Common;
using LLFM.CAT.Model;

public class ImgUpload : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        string[] filetype = { ".gif", ".png", ".jpg", ".jpeg", ".bmp" };

        try
        {
            HttpPostedFile jpeg_image_upload = context.Request.Files["Filedata"];
            int imgWidth;
            int imgHeight;
            string subPath = string.Empty;
            string fullPath = Common.FileUploadHelper.BuildSavePath(jpeg_image_upload, System.Configuration.ConfigurationManager.AppSettings["ImagePath"], "ProductImg", out subPath,"");
            // string mapPaht = Server.MapPath("");
            Common.Enums.FileUploadResult result = Common.FileUploadHelper.FileUpload(jpeg_image_upload, fullPath, 5242880, filetype, "", out imgWidth, out imgHeight);
            if (result == Common.Enums.FileUploadResult.文件上传成功)
            {

                M_ProductsImages imageM = new M_ProductsImages();
                //imageM.ImageUrl = fullPath;

                string photoJson = JsonHelper.Serialize<M_ProductsImages>(imageM);
                context.Response.ContentType = "text/plain";
                context.Response.StatusCode = 200;
                context.Response.Write(photoJson);
            }
            else
            {
                context.Response.StatusCode = 500;
                context.Response.Write("An error occured" + result.ToString());
                context.Response.End();
            }
        }
        catch
        {
            context.Response.StatusCode = 500;
            context.Response.Write("An error occured");
            context.Response.End();
        }
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }

}